package com.xquant.common.engine.xPP.response;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.ArrayList;
import java.util.List;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class CalcResult {
    private String errorCode;
    private String errorMsg;
    private String responseCode;
    private CalcMarket calcMarket;
    private List<CalcScene> calcScene;
    private List<CalcPaymentInfo> calcPaymentInfo;
    private List<CalcAccrualDetail> calcAccrualDetail;
    private List<CalcAssetInfo> calcAssetInfo;
    private List<CalcAssetDetail> calcAssetDetail;
    private CalcCDS calcCDS;
    private List<ReadFixingDate> readFixingDates;
    private List<CalcMaturityPayment> calcMaturityPayment;
    private CalcTrial calcTrial;

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public String getResponseCode() {
        return responseCode;
    }

    public void setResponseCode(String responseCode) {
        this.responseCode = responseCode;
    }

    public CalcMarket getCalcMarket() {
        return calcMarket;
    }

    public void setCalcMarket(CalcMarket calcMarket) {
        this.calcMarket = calcMarket;
    }

    public List<CalcScene> getCalcScene() {
        return calcScene;
    }

    public void setCalcScene(List<CalcScene> calcScene) {
        this.calcScene = calcScene;
    }

    public List<CalcPaymentInfo> getCalcPaymentInfo() {
        return calcPaymentInfo;
    }

    public void setCalcPaymentInfo(List<CalcPaymentInfo> calcPaymentInfo) {
        this.calcPaymentInfo = calcPaymentInfo;
    }

    public List<CalcAccrualDetail> getCalcAccrualDetail() {
        return calcAccrualDetail;
    }

    public void setCalcAccrualDetail(List<CalcAccrualDetail> calcAccrualDetail) {
        this.calcAccrualDetail = calcAccrualDetail;
    }

    public List<CalcAssetInfo> getCalcAssetInfo() {
        return calcAssetInfo;
    }

    public void setCalcAssetInfo(List<CalcAssetInfo> calcAssetInfo) {
        this.calcAssetInfo = calcAssetInfo;
    }

    public List<CalcAssetDetail> getCalcAssetDetail() {
        return calcAssetDetail;
    }

    public void setCalcAssetDetail(List<CalcAssetDetail> calcAssetDetail) {
        this.calcAssetDetail = calcAssetDetail;
    }

    public List<CalcMaturityPayment> getCalcMaturityPayment() {
        return calcMaturityPayment;
    }

    public void setCalcMaturityPayment(List<CalcMaturityPayment> calcMaturityPayment) {
        this.calcMaturityPayment = calcMaturityPayment;
    }

    public CalcTrial getCalcTrial() {
        return calcTrial;
    }

    public void setCalcTrial(CalcTrial calcTrial) {
        this.calcTrial = calcTrial;
    }

    public CalcCDS getCalcCDS() {
        return calcCDS;
    }

    public void setCalcCDS(CalcCDS calcCDS) {
        this.calcCDS = calcCDS;
    }

    public List<ReadFixingDate> getReadFixingDates() {
        return readFixingDates;
    }

    public void setReadFixingDates(List<ReadFixingDate> readFixingDates) {
        this.readFixingDates = readFixingDates;
    }

    public static CalcResult merge(List<CalcResult> results) {
        CalcResult ret = results.get(0);
        for (int i = 1; i < results.size(); i++) {
            CalcResult result = results.get(i);
            if (result.getCalcMarket() != null) {
                if (ret.getCalcMarket() == null) {
                    ret.setCalcMarket(new CalcMarket());
                }
                ret.getCalcMarket().merge(result.getCalcMarket());
            }
            if (result.getCalcPaymentInfo() != null) {
                if (ret.getCalcPaymentInfo() == null) {
                    ret.setCalcPaymentInfo(new ArrayList<>());
                }
                ret.getCalcPaymentInfo().addAll(result.getCalcPaymentInfo());
            }
            if (result.getCalcScene() != null) {
                if (ret.getCalcScene() == null) {
                    ret.setCalcScene(new ArrayList<>());
                }

                ret.getCalcScene().addAll(result.getCalcScene());

            }
            if (result.getReadFixingDates() != null) {
                if (ret.getReadFixingDates() == null) {
                    ret.setReadFixingDates(new ArrayList<>());
                }
                ret.getReadFixingDates().addAll(result.getReadFixingDates());
            }
        }
        return ret;
    }
}
